<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
	<title>Fancytree - Example: ext-clones</title>
<!--
	<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css">
	<script src="//code.jquery.com/jquery-1.12.1.min.js" type="text/javascript"></script>
	<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js" type="text/javascript"></script>
 -->
	<script src="../lib/jquery.js" type="text/javascript"></script>
	<script src="../lib/jquery-ui.custom.js" type="text/javascript"></script>

	<link href="../src/skin-win8/ui.fancytree.css" class="skinswitcher" rel="stylesheet" type="text/css">
	<script src="../src/jquery.fancytree.js" type="text/javascript"></script>
	<script src="../src/jquery.fancytree.clones.js" type="text/javascript"></script>

	<!-- Start_Exclude: This block is not part of the sample code -->
	<link href="../lib/prettify.css" rel="stylesheet">
	<script src="../lib/prettify.js" type="text/javascript"></script>
	<link href="sample.css" rel="stylesheet" type="text/css">
	<script src="sample.js" type="text/javascript"></script>
	<!-- End_Exclude -->

<style type="text/css">
span.fancytree-node.fancytree-clone span.fancytree-title {
	color: blue;
}
span.fancytree-node.fancytree-clone span.fancytree-title:after {
	content: "";
	background: url("") 100% 50% no-repeat;
	padding-right: 13px;
}


span.fancytree-node.fancytree-active-clone {
  border-color: blue;
  -moz-animation: flash 1s ease-out;
  -moz-animation-iteration-count: 1;
  -webkit-animation: flash 1s ease-out;
  -webkit-animation-iteration-count: 1;
  -ms-animation: flash 1s ease-out;
  -ms-animation-iteration-count: 1;
}

@-ms-keyframes flash {
	0% { background-color:none;}
	50% { background-color:#fbf8b2;}
	100% {background-color:none;}
}
@-moz-keyframes flash {
	0% { background-color:none;}
	50% { background-color:#fbf8b2;}
	100% {background-color:none;}
}
@-ms-keyframes flash {
	0% { background-color:none;}
	50% { background-color:#fbf8b2;}
	100% {background-color:none;}
}
</style>


<!-- Add code to initialize the tree when the document is loaded: -->
<script type="text/javascript">

var SOURCE = [
			  {title: "Item 1", key: "node1"},
			  {title: "Folder 2", folder: true, expanded: true, key: "node2",
				  children: [
					  {title: "Sub-item 2.1, refKey=3", key: "node2.1", refKey: "3"},
					  {title: "Sub-item 2.2", key: "node2.2", refKey: "2"}
				  ]
			  },
			  {title: "Folder 3", folder: true, expanded: true, key: "node3",
				  children: [
					  {title: "Sub-item 2.1", key: "node3.1", selected: false,
						  children: [
									  {title: "Sub-item 3.1.1", key: "node3.1.1"},
									  {title: "Sub-item 3.1.2", key: "node3.1.2", refKey: "2"}
								  ]
						  },
					  {title: "Sub-item 2.2", key: "node3.2"}
				  ]
			  },
			  {title: "Folder 4", folder: true, expanded: true, key: "node4",
				  children: [
					  {title: "Sub-item 2.1", key: "node4.1", refKey: "1"},
					  {title: "Sub-item 2.2", key: "node4.2", refKey: "1", selected: false},
					  {title: "Sub-item 2.3 (unselectable)", key: "node4.3", selected: false, unselectable: true}
				  ]
			  },
			  {title: "Item 3", key: "node5", lazy: true}
		  ];
		  // Lazy sub nodes
		  var SOURCE_2 = [
			  {title: "Lazy Folder 1", folder: true, expanded: true,
				  children: [
					  {title: "Lazy Sub-item 1.1", selected: false,
						  children: [
									  {title: "Sub-item 2.1.1"},
									  {title: "Sub-item 2.1.2", selected: false}
								  ]
						  },
					  {title: "Sub-item 2.2"}
				  ]
			  }
		  ];

	$(function(){
		$("#tree").fancytree({
			extensions: ["clones"],
//            source: { url: "ajax-tree-plain.json" },
			source: SOURCE,
			clones: {
				highlightClones: true
			},
			lazyLoad: function(e, data) {
				data.result = {url: "ajax-sub2.json"}
			},
			activate: function(e, data){
				var clones = data.node.getCloneList();
				if( clones ) {
//					alert("Clones: "+ $.map(clones, function(n){ return "" + n;}).join(", "));
				}
			}
		});

		addSampleButton({
			label: "find clones",
			newline: false,
			code: function(){
				var tree = $("#tree").fancytree("getTree"),
					node3 = tree.getNodeByKey("node3");
				alert("refKey '2' = " + tree.getNodesByRef("2"));
				alert("refKey '2' below 'node3'' = " + tree.getNodesByRef("2", node3));
			}
		});
		addSampleButton({
			label: "remove",
			newline: false,
			code: function(){
				var tree = $("#tree").fancytree("getTree"),
					node = tree.getActiveNode();
				node.remove();
			}
		});
	});
</script>
</head>

<body class="example">
	<h1>Example: 'clones' extension</h1>
	<div class="description">
		<p>
			Clones.
		</p>
		<p>
		</p>
		<p>
			<b>Status:</b> beta.
			<b>Details:</b>
			<a href="https://github.com/mar10/fancytree/wiki/ExtClones"
				target="_blank" class="external">ext-clones</a>.
		</p>
	</div>

	<div>
		<label for="skinswitcher">Skin:</label> <select id="skinswitcher"></select>
	</div>
	<p id="sampleButtons">
	</p>
	<!-- Add a <table> element where the tree should appear: -->
	<div id="tree">
	</div>

	<!-- Start_Exclude: This block is not part of the sample code -->
	<hr>
	<p class="sample-links  no_code">
		<a class="hideInsideFS" href="https://github.com/mar10/fancytree">jquery.fancytree.js project home</a>
		<a class="hideOutsideFS" href="#">Link to this page</a>
		<a class="hideInsideFS" href="index.html">Example Browser</a>
		<a href="#" id="codeExample">View source code</a>
	</p>
	<pre id="sourceCode" class="prettyprint" style="display:none"></pre>
	<!-- End_Exclude -->
</body>
</html>
